/*
 *  HeartBeatController.h
 *  project8
 *
 *  Created by Luca Gobbo on 21-06-10.
 *  Copyright 2010 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef _HEARTBEATCONTROLLER_H
#define _HEARTBEATCONTROLLER_H

#include "Led.h"
#include "InfraredSensor.h"
#include "pRTOS.h"
//#include "IRSListener.h"
#include "Timer.h"
#include "TImerListener.h"
#include "SpeakerSwitch.h"


class InfraredSensor; // forward decleration


 
class HeartBeatController : public cTask , public IRSListener , public TimerListener {
	
	
public:
    HeartBeatController(InfraredSensor *sensor);
    void timeout(Timer * src);
    void init();
    void update();      
    void heartBeat(void);
    int getHbCur();
    int getHbAvg();
    int getHbLow();
    int getHbHigh();
    void run();
    void disable();
    
    
private:
    enum Status {
      RUN,
      STB,
      STS
    
    };
    Status state;
    
    double beats;
    double time;
    double prevTime;
    double prevLedTime;
    double hbAVG;
    double hbCUR;
    double hbHIGH;
    double hbLOW;
    double tzMAX;
    double tzMIN;
    char first;
    
    InfraredSensor * theInfraredSensor;
    SpeakerSwitch theSpeakerSwitch;
    Led theLed;
    cEventFlagGroup hbFlags;
    Timer  timer;
    Timer  timer2;
   
    enum flags{
      hbFlagNo,
      timerFlagNo,
      ledFlagNo
    };
};


#endif